home *** CD-ROM | disk | FTP | other *** search
-
- ' This example shows how you can link C-subprograms to BASIC-programs
- ' The C-program was compiled using ZC from Fish-Disk 314
-
- OPTION TRYCLIWINDOW
- OPTION ALLPCRELATIVE
-
- INPUT "Number";a&
- CALL IsPrime (a&),IsPrime&
-
- IF IsPrime& THEN
- PRINT a&;" is a prime number"
- ELSE
- PRINT a&;" is no prime number"
- END IF
-
- SUB EXTERNAL IsPrime (Number&,IsPrime&) STATIC
-
- ' The SUB-command does the following things:
- ' - Whenever you call 'IsPrime' via the CALL-command the parameters of the
- ' CALL-command are converted to the types specified in the SUB-command.
- ' - The C or assembly program is called. It must have the name '_ISPRIME'
- ' (must be in upper case).
- ' Unlike in C-programs 'Cursor' pushes the left parameters first, not
- ' last. Thus the C-program must reverse the order of the parameters:
- ' In this case
- ' IsPrime(isprime,number)
- ' is correct, but not
- ' IsPrime(number,isprime).
- ' - At the moment it is not possible to get the result of the C-function
- ' (returned in D0), but the C-Program can modify the variables on the
- ' stack. Variables not enclosed in brackets get their new value from there
- ' (where they perhaps were modified by the C-program).
- ' In this example program the result is returned in 'IsPrime&'.
- ' - 'Cursor' will not create an executable program but an object file, which
- ' can be linked with the C-routines.
- ' The object file created by 'Cursor' must be the first file linked!
- '
- ' Note that the new program might not be 'pure' any more, this depends
- ' on the linked C or assembly language routines.
-
- ' 'IsPrime&' is a long and not an int variable because I had problems with
- ' ZC and int/short variables.
-
-